const domain = 'http://sys.zhaojixie.ry2.itemjia.com';
const api = {
    smsVerify: domain + '/api/sms/verify',//发送短信验证码
    smsPwd: domain + '/api/user/sms/pwd', //通过短信修改password
    addJixie: domain + '/api/table/append/zhaojixie', // 增加机械
    jixieDetail: domain + '/api/table/detail/zhaojixie' , //找机械详情
    orderAppend: domain + '/api/order/append', //成订单
    zhaojixieOrder: domain + '/api/table/list/zhaojixie_order_view', // 机械订单
    updateJixieOrder: domain + '/api/table/update/zhaojixie_order', // 更新机械订单
    orderDetai:  domain + '/api/table/detail/zhaojixie_order',
    orderDetaiView:  domain + '/api/table/detail/zhaojixie_order_view',
    jixielist: domain + '/api/table/list/zhaojixie', //机械列表
    orderPay: domain + '/api/pay/order', //支付
    saveUser: domain + '/api/user/update', //保存
}
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    var q = window.location.pathname.substr(1).match(reg_rewrite);
    if(r != null){
        return unescape(r[2]);
    }else if(q != null){
        return unescape(q[2]);
    }else{
        return null;
    }
}
function makeSign(obj) {
    if (!obj) { console.log('需要加密的数组对象为空') }
    var keys = [], sign = [];
    console.info('obj', obj)
    Object.keys(obj).forEach(function (key) {
        console.info('test', key, obj[key])
        if (obj[key] === undefined || obj[key] === "") {
            delete obj[key];
        }
        else {
            keys.push(key);
        }
    })
    keys.sort();
    console.info('keys', keys)
    keys.forEach(function (i, key) {
        console.info(i, key)
        console.info('eee', obj[i])
        sign.push(i + "=" + obj[i]);
    })
    console.info('sign', sign, sign.join("&") + "&key=" + 'www.rsseasy.com')
    let t = md5(sign.join("&") + "&key=" + 'www.rsseasy.com');
    return t;
}
function request(object, cb) {
    let signtoken = makeSign(object.data);
    if (Object.keys(object.data).length !== 0) {
        object.data.signtoken = signtoken
    }
    $.ajax({
        url: object.url,
        type: object.type,
        data: object.data,
        dataType: 'json',
        contentType: 'application/x-www-form-urlencoded',
        headers: {
            Accept: "application/json; charset=utf-8",
            usertoken: localStorage.usertoken,
            tokenmyid: localStorage.tokenmyid
        },
        success: function (res) {
            cb(res)
        },
        fail: function (err) {
            console.info(err,'err');
        }
    })
}
/*机械类型品牌*/
function getClassfiyid(id) {
    var zhaojixieclassify = window.rydata.zhaojixieclassify;
    for (let i in zhaojixieclassify) {
        if (i === id) {
            return zhaojixieclassify[i][0]
        }
    }
}
/*品牌型号transform*/
function getTrademarklid (id) {
    var zhaojixietrademark = window.rydata.zhaojixietrademark;
    for (let j in zhaojixietrademark) {
        if (j === id) {
            return zhaojixietrademark[j][0]
        }
    }
}
/*时间*/
function formatTest (str) {
    var date = new Date(str * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    const result = `${Y}${M}${D}`
    return result
}
function formatTestHour (str) {
    var date = new Date(str * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    const result = `${Y}${M}${D} ${h}${m}${s}`;
    return result
}
function formatTest1 (str) {
    var date = new Date(str * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    const result = `${Y}${M}${D}`;
    return result
}
function formatTest2 (str) {
    var date = new Date(str * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    const result = `${h}${m}${s}`;
    return result
}
/*获得城市选择*/
function getFirstCity() {
    const first = []
    for (let j in AreaListData) {
        if(AreaListData[j][1] === '0') {
            first.push({id: j, value: AreaListData[j][0]});
        }
    }
    for( let i = 0; i < first.length; i ++) {
        first[i].childs = secondCity(first[i].id);
    }
    return first;
}

function secondCity(id) {
    var second = [];
    for (let j in AreaListData) {
        if(AreaListData[j][1] === id) {
            second.push({id: j, value: AreaListData[j][0]});
        }
    }
    return second;
}
/*结算方式*/
function getClearingform(str) {
    const strJson = {'1': '现款', '2': '签单', '3': '月付'}
    return strJson[str];
}
/*是否*/
function isYes(str) {
    console.info(parseInt(str));
    const strJson = {1: '是', 0: '否'}
    return strJson[str];
}
/*展示load*/
function showLoad() {
    RssWin.MaskLayer.show();
    RssWin.LoadBox.show();
}
function hideLoad() {
    RssWin.LoadBox.close();
    RssWin.MaskLayer.close();
}
function getState(id) {
    const JSON = { 0:'待同意',1: '待支付',2: '已成交',3: '已撤销',4:'已过期',5: '确认成交'};
    return JSON[id]
}